<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>环形子数组的最大和</title>
</head>
<body>
  <script>
    function fn(nums) {
      let pre = 0, maxAns = nums[0];
      nums.forEach((x) => {
        pre = Math.max(pre + x, x);
        maxAns = Math.max(maxAns, pre);
      });
      return maxAns;
    }
    console.log(fn([1, -2, 3, -2]))
  </script>
</body>
</html>